package rs.graphics;// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 

import rs.graphics.DrawingArea;

import java.awt.*;
import java.awt.image.*;

public final class GraphicsBuffer
        implements ImageProducer, ImageObserver {

    public GraphicsBuffer(int w, int h, Component component) {
        width = w;
        height = h;
        pixelArr = new int[w * h];
        colorModel = new DirectColorModel(32, 0xff0000, 65280, 255);
        image = component.createImage(this);
        setupImage();
        component.prepareImage(image, this);
        setupImage();
        component.prepareImage(image, this);
        setupImage();
        component.prepareImage(image, this);
        initDrawingArea();
    }

    public void initDrawingArea() {
        DrawingArea.initDrawingArea(height, width, pixelArr);
    }

    public void drawGraphics(int i, Graphics g, int k) {
        setupImage();
        g.drawImage(image, k, i, this);
    }

    public synchronized void addConsumer(ImageConsumer imageconsumer) {
        imageConsumer = imageconsumer;
        imageconsumer.setDimensions(width, height);
        imageconsumer.setProperties(null);
        imageconsumer.setColorModel(colorModel);
        imageconsumer.setHints(14);
    }

    public synchronized boolean isConsumer(ImageConsumer imageconsumer) {
        return imageConsumer == imageconsumer;
    }

    public synchronized void removeConsumer(ImageConsumer imageconsumer) {
        if (imageConsumer == imageconsumer)
            imageConsumer = null;
    }

    public void startProduction(ImageConsumer imageconsumer) {
        addConsumer(imageconsumer);
    }

    public void requestTopDownLeftRightResend(ImageConsumer imageconsumer) {
        System.out.println("TDLR");
    }

    private synchronized void setupImage() {
        if (imageConsumer != null) {
            imageConsumer.setPixels(0, 0, width, height, colorModel, pixelArr, 0, width);
            imageConsumer.imageComplete(2);
        }
    }

    public boolean imageUpdate(Image image, int i, int j, int k, int l, int i1) {
        return true;
    }

    public final int[] pixelArr;
    private final int width;
    private final int height;
    private final ColorModel colorModel;
    private ImageConsumer imageConsumer;
    private final Image image;
}
